home *** CD-ROM | disk | FTP | other *** search
- // GETINFO SCRIPTING
- // Imports from csfd.cz
-
- (***************************************************
- * by Dmitry501 *
- * *
- * For use with Ant Movie Catalog 3.4.0 *
- * www.antp.be/software/moviecatalog *
- * *
- * This program is free software; you can *
- * redistribute it and/or modify it under the *
- * terms of the GNU General Public License as *
- * published by the Free Software Foundation; *
- * either version 2 of the License, or (at your *
- * option) any later version. *
- ***************************************************)
-
- program Csfd_cz;
- const
- BaseAddress = 'http://www.csfd.cz/';
- var
- MovieName: string;
-
- function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
- var
- i: Integer;
- begin
- result := -1;
- if StartAt < 0 then
- StartAt := 0;
- for i := StartAt to List.Count-1 do
- if Pos(Pattern, List.GetString(i)) <> 0 then
- begin
- result := i;
- Break;
- end;
- end;
-
- function GetDirector(Line: string): String;
- var BeginPos : Integer;
- begin
- result := '';
- BeginPos := Pos('Re₧ie:', Line);
- if BeginPos > 0 then
- begin
- Delete(Line,1,BeginPos+5);
- BeginPos := Pos('<br>', Line);
- if BeginPos = 0 then BeginPos := Length(Line);
- result := copy(Line, 1, BeginPos);
- HTMLDecode(result);
- HTMLRemoveTags(result);
- end;
- result := Trim(result);
- end;
-
- function GetActor(Line: string): String;
- var BeginPos : Integer;
- begin
- result := '';
- BeginPos := Pos('Hrajφ:', Line);
- if BeginPos > 0 then
- begin
- Delete(Line,1,BeginPos + 5);
- BeginPos := Pos('<br>', Line);
- if BeginPos = 0 then BeginPos := Length(Line);
- result := copy(Line, 1, BeginPos);
- HTMLDecode(result);
- HTMLRemoveTags(result);
- end;
- result := Trim(result);
- end;
-
- function GetTitle(Line: string): String;
- var BeginPos : Integer;
- begin
- result := '';
- BeginPos := Pos('<img src=''/images/flag_52.gif', Line);
- if BeginPos > 0 then
- begin
- Delete(Line,1,BeginPos-1);
- BeginPos := Pos('</table>', Line);
- if BeginPos = 0 then BeginPos := Length(Line);
- result := copy(Line, 1, BeginPos);
- HTMLDecode(result);
- HTMLRemoveTags(result);
- MovieName := GetField(fieldTranslatedTitle);
- MovieName := MovieName + ' (' + result + ')';
- SetField(fieldTranslatedTitle,MovieName);
- Delete(Line,1,BeginPos-1);
- end
-
- BeginPos := Pos(' ', Line);
- if BeginPos > 0 then
- begin
- Delete(Line,BeginPos, Length(Line));
- result := Line;
- HTMLDecode(result);
- HTMLRemoveTags(result);
- end;
- result := Trim(result);
- end;
-
- function GetCategory(Line: string): String;
- var BeginPos : Integer;
- begin
- result := '';
- BeginPos := Pos(' ', Line);
- if BeginPos > 0 then
- begin
- Delete(Line,1,BeginPos + 9);
- BeginPos := Pos('<br>', Line);
- if BeginPos = 0 then BeginPos := Length(Line);
- result := copy(Line, 1, BeginPos-1);
- HTMLDecode(result);
- HTMLRemoveTags(result);
- end;
- result := Trim(result);
- SetField(fieldCategory, result);
- result := '';
- Delete(Line,1,BeginPos-1);
- BeginPos := Pos('<br>', Line);
- if BeginPos > 0 then
- begin
- Delete(Line,1,BeginPos + 3);
- BeginPos := Pos('<p>', Line);
- if BeginPos = 0 then BeginPos := Length(Line);
- result := copy(Line, 1, BeginPos-1);
- HTMLDecode(result);
- HTMLRemoveTags(result);
- end;
- result := Trim(result);
- SetField(fieldCountry, result);
- end;
-
- procedure AnalyzePage(Address: string);
- var
- Page: TStringList;
- LineNr : Integer;
- Line, Value : String;
- BeginPos, EndPos : Integer;
- FilmName, FilmAddr : String;
- begin
- Page := TStringList.Create;
- Page.Text := GetPage(Address);
- LineNr := FindLine('databßze</title>', Page, 0);
- if LineNr = -1 then
- begin
- AnalyzeMoviePage(Address);
- end
- else
- begin
- LineNr := FindLine('Nebyly nalezeny ₧ßdnΘ', Page, 0);
- if LineNr = -1 then
- begin
- LineNr := FindLine('<a href="film.', Page, 0);
- if LineNr > -1 then
- begin
- PickTreeClear;
- PickTreeAdd('Filmy: ' + MovieName, '');
- Line := Page.GetString(LineNr);
- repeat
- BeginPos := Pos('<a href="',Line);
- If BeginPos > 0 Then
- begin
- EndPos := Pos('">',Line);
- if EndPos = 0 Then EndPos := Length(Line);
- FilmAddr := Copy(Line, BeginPos+9, EndPos-BeginPos-9);
- HTMLDecode(FilmAddr);
- HTMLRemoveTags(FilmAddr);
- EndPos := Pos('<br>',Line);
- if EndPos = 0 Then EndPos := Length(Line);
- FilmName := Copy(Line, BeginPos, EndPos-BeginPos);
- HTMLDecode(FilmName);
- HTMLRemoveTags(FilmName);
- PickTreeAdd(FilmName, BaseAddress + FilmAddr);
- Delete(Line,1,EndPos+3);
- end;
- until BeginPos <1;
- If PickTreeExec(Address) Then
- AnalyzeMoviePage(Address);
- end;
- end;
- end;
- end;
-
- procedure AnalyzeMoviePage(Address: string);
- var
- Page: TStringList;
- LineNr : Integer;
- Line, Value : String;
- BeginPos, EndPos : Integer;
- begin
- Page := TStringList.Create;
- Page.Text := GetPage(Address);
- LineNr := FindLine('<div class="nazovfilmu">', Page, 0);
- if LineNr > -1 then
- begin
-
- Line := Page.GetString(LineNr+1);
- HTMLDecode(Line);
- HTMLRemoveTags(Line);
- Value := Trim(Line);
- SetField(fieldTranslatedTitle, Value);
-
- Line := Page.GetString(LineNr+2);
- Value := GetDirector(Line);
- SetField(fieldDirector, Value);
- Value := GetActor(Line);
- SetField(fieldActors, Value);
- Value := GetTitle(Line);
- SetField(fieldOriginalTitle, Value);
- Value := GetCategory(Line);
- end;
- // picture
- LineNr := FindLine('style="padding-left: 10px"', Page, 0);
- if LineNr > -1 then
- begin
- Line := Page.GetString(LineNr);
- BeginPos := pos('<img src="', Line) + 10;
- if BeginPos > 10 then
- begin
- EndPos := pos('" width="', Line);
- Value := copy(Line, BeginPos, EndPos - BeginPos);
- Value := BaseAddress + Value;
- GetPicture(Value, False);
- end;
- end;
- // Info
- LineNr := FindLine('id="plot_full"', Page, 0);
- if LineNr > -1 then
- begin
- Value := Page.GetString(LineNr+1);
- HTMLDecode(Value);
- HTMLRemoveTags(Value);
- SetField(fieldDescription, Trim(Value));
- end;
- // URL
- SetField(fieldURL, Address);
- DisplayResults;
- end;
-
- begin
- if CheckVersion(3,4,0) then
- begin
- MovieName := GetField(fieldOriginalTitle);
- if MovieName = '' then
- MovieName := GetField(fieldTranslatedTitle);
- if Input('Import movie from www.csfd.cz', 'Enter the title of the movie:', MovieName) then
- begin
- AnalyzePage(BaseAddress + 'index.php?action=hledat&hledej='+UrlEncode(MovieName));
- end;
- end else
- ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)');
- end.
-